
var DatePicker = {
	datePicker:null,

	create:function(attId){
		if(this.datePicker != null)
			return;
			
		var basepath = getLibURI();
		var docw = document.body.scrollLeft + document.body.clientWidth;
		var doch = document.body.scrollTop + document.body.clientHeight;
		var dp = document.createElement("<div style='position:absolute;background:url("+basepath+"default/image/blank.gif);left:0;top:0;'>");
		setWidth(dp, docw);
		setHeight(dp, doch);
		DatePicker.datePicker = dp;
		dp.innerHTML = "<iframe id='datePickerFrame' allowTransparency='true'  onload='document.all.datePickerFrame.style.height=window.datePickerFrame.document.body.scrollHeight;'  src='"+basepath+"/template/DatePicker.html' FRAMEBORDER=0 SCROLLING=NO style='position:absolute;width:200'></iframe>";
		document.body.appendChild(dp);
		dp.attId = attId;
		dp.today = document.getElementById(attId).value;

		var w = document.body.scrollWidth > document.body.clientWidth ? document.body.scrollWidth : document.body.clientWidth;
		var datePickerFrame = document.all.datePickerFrame;
		var x = event.clientX + document.body.scrollLeft;
		datePickerFrame.style.left = x - 10;
		if(datePickerFrame.offsetLeft+datePickerFrame.offsetWidth > w)
			datePickerFrame.style.left = x - datePickerFrame.offsetWidth;
			
		var h = document.body.scrollHeight > document.body.clientHeight ? document.body.scrollHeight : document.body.clientHeight;
		var y = event.clientY + document.documentElement.scrollTop;
		
		datePickerFrame.style.top = y;
		if(datePickerFrame.offsetTop + datePickerFrame.offsetHeight > h){
			datePickerFrame.style.top = y - datePickerFrame.offsetHeight - 45;
		}
		dp.onclick = this.endDP;
		
		//dojo.event.browser.stopEvent(event);
		event.returnValue = false;
		event.cancelBubble = true;
		
		//var today = document.getElementById(DatePicker.datePicker.attId).value;
		//if(today){
		//	frames['datePickerFrame'].window.strToday = today;
		//	alert(frames['datePickerFrame'].window.today)
			//document['datePickerFrame'].Calendar();
		//}
	},

	endDP:function(date){
		if(date){
			document.getElementById(DatePicker.datePicker.attId).value = date;
		}
		
		document.body.removeChild(DatePicker.datePicker);
		DatePicker.datePicker = null;
	}
};